#include "splashscreen.h"
#include <QDebug>
#include <QQmlComponent>
#include <QQuickItem>

SplashScreen::SplashScreen(QWindow *parent)
    : QQuickView(parent)
{
    // 设置窗口属性
    setFlags(Qt::Window | Qt::FramelessWindowHint);
    setResizeMode(QQuickView::SizeRootObjectToView);
    
    // 加载QML文件 - 优化版启动画面(无OpenGL依赖)
    setSource(QUrl("qrc:/qml/SplashScreen.qml"));
    qDebug() << "加载启动画面";
    
    if (status() == QQuickView::Error) {
        qDebug() << "启动画面加载失败!";
        QList<QQmlError> errors = this->errors();
        for (const QQmlError &error : errors) {
            qDebug() << "QML错误:" << error.toString();
        }
        return;
    }
    
    // 设置窗口大小
    setWidth(1024);
    setHeight(600);
    
    // 获取根对象并连接finished信号
    QQuickItem *rootObject = this->rootObject();
    if (rootObject) {
        connect(rootObject, SIGNAL(finished()), this, SLOT(onQmlFinished()));
        qDebug() << "启动画面初始化成功";
    } else {
        qDebug() << "无法获取QML根对象";
    }
}

SplashScreen::~SplashScreen()
{
}

void SplashScreen::onQmlFinished()
{
    qDebug() << "启动画面完成";
    emit splashFinished();
}
